import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
const state = {
    count:0
};
const mutations = {
    add(state,num){
        console.log(state);
        console.log(num);
        state.count += num;
    },
    /* addObj(state,obj){
        console.log(obj);
        state.count += obj.num;
    } */
    addObj(state,{num,info}){
        console.log(info);
        state.count += num;
    },
    // actions的讲解以减法为
    decrement(state,num){
        state.count -= num;
    },
    /* decrementObj(state,obj){
        console.log(obj);
        state.count -= obj.num;
    } */
    decrementObj(state,num){
        // console.log(obj);
        state.count -= num;
    }
};
const actions = {
    decrementAct({commit,state},num){
        console.log(state);
        commit('decrement',num);
    },
    decrementObjAct({commit,state},{num}){
        console.log(state);
        commit('decrementObj',num);
    }
};
const getters = {
    evenOrOdd(){
        return state.count % 2 == 0 ? "偶数" : "奇数";
    }
};

export default  new Vuex.Store({
    // ...
    state,
    mutations,
    actions,
    getters
})